# Copyright (C) 2009,2010,2011,2012  Marco Restelli
#
# This file is part of:
#   FEMilaro -- Finite Element Method toolkit
#
# FEMilaro is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# FEMilaro is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FEMilaro; If not, see <http://www.gnu.org/licenses/>.
#
# author: Marco Restelli                   <marco.restelli@gmail.com>

# This Makefile handles the dependencies among the subfolders of the
# src folder. It should be called by the main Makefile, where the
# compiler options are defined, and it should never be modified
# directly: all the configuration options are in the main Makefile.

# General settings -----------------------------------

# clear unfinished targets
.DELETE_ON_ERROR:
# exported variables (the same as in the main Makefile)
export EXPORTED_VARS $(EXPORTED_VARS)
# define the phony targets
# Notice that at this level we don't know the detailed prerequisites
# of the main targets, so we have to define all the main targets as
# phony. This way, we always cd into the particular folder and check
# the detailed prerequisites.
.PHONY: clean allclean doc \
        libfml_general_utilities.a \
        libode.a ode-test \
	libfml_linear_solvers.a linsolver-test \
	libfem.a \
        libsc.a \
        wandzuraxiao cools-encyclopedia \
	cg ldgh ldghf psi               \
	cg-stokes cg-ns dg-comp         \
	cg-dd hmap                      \
	vp-dg

# Main targets ---------------------------------------

wandzuraxiao cools-encyclopedia: libfml_general_utilities.a
	cd ./numerical-quadrature; $(MAKE) $@

cg ldgh ldghf psi scharfetter_gummel: libfml_general_utilities.a libfml_linear_solvers.a libfem.a
	cd ./ADR; $(MAKE) $@

cg-stokes cg-ns dg-comp: libfml_general_utilities.a libode.a libfml_linear_solvers.a libfem.a
	$(MAKE) --directory=./NS $@

hmap: libfml_general_utilities.a libode.a libfml_linear_solvers.a
	cd ./LC; $(MAKE) $@

vp-dg: libfml_general_utilities.a libode.a libfml_linear_solvers.a libfem.a
	$(MAKE) --directory=./VE $@

libfml_general_utilities.a eigen-test:
	$(MAKE) --directory=./fml_general_utilities $@

libode.a ode-test: libfml_general_utilities.a
	$(MAKE) --directory=./time-integrators $@

libfml_linear_solvers.a linsolver-test: libfml_general_utilities.a
	$(MAKE) --directory=fml_linear_solvers $@

libfem.a: libfml_general_utilities.a
	$(MAKE) --directory=./fem $@

libsc.a: libfml_general_utilities.a libfem.a
	$(MAKE) --directory=./ADR $@

library: libfml_general_utilities.a libfml_linear_solvers.a libsc.a libode.a libfem.a

doc:
	doxygen Doxyfile

clean:
	$(MAKE) --directory=./fml_general_utilities clean
	$(MAKE) --directory=./time-integrators      clean
	$(MAKE) --directory=./fml_linear_solvers    clean
	$(MAKE) --directory=./fem                   clean
	$(MAKE) --directory=./numerical-quadrature  clean
	$(MAKE) --directory=./ADR                   clean
	$(MAKE) --directory=./NS                    clean
	$(MAKE) --directory=./LC                    clean
	$(MAKE) --directory=./VE                    clean

allclean: clean
	rm -Rf ./../doc/html ./../doc/latex
